package com.bj58.data.hadoop.info.dimension;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.bj58.data.hadoop.info.entry.InfoEntry;

public class param extends IDimension{

	public static final String ROWKEY_PREFIX = "param";
	
	public param()
	{
		rowKeyPrefix = ROWKEY_PREFIX;
		sortID = DimensionSort.param;
	}
	
	@Override
	public void setCareValues(String values) {
		// TODO Auto-generated method stub
		String[] array = values.split(",");
		for(String val:array)
		{
			String[] oneParam = val.split("=");
			String oneParamKey = oneParam[0];
			String oneParamValue = oneParam[1];
			if(oneParamValue.equals("A"))
			{
				this.careValues.put(oneParamKey,"");//6821
			}
			else
			{
				String[] oneParamVals = oneParamValue.split(" ");
				for(String oneParamVal:oneParamVals)
				{
					this.careValues.put(oneParamKey+"="+oneParamVal, "");//6821=513660|513661
				}
			}
		}
		//System.out.println(careValues);
	}

	@Override
	public boolean inCareValues(InfoEntry infoEntry) {
		// TODO Auto-generated method stub
		Map<String,String> paramMap = infoEntry.getParams();//信息map
		//System.out.println(paramMap.toString());
		if(paramMap.size()>0)
		{
			Iterator<Entry<String, String>> it = paramMap.entrySet().iterator();
			while(it.hasNext())
			{
				Entry<String, String> entry = it.next();
				String key = entry.getKey(); //6821
				String value = entry.getValue(); //513660|513661
				if(careValues.containsKey(key))
				{
					return true;
				}
				else if(careValues.containsKey(key+"="+value))
				{
					return true;
				}
			}
		}
		return false;
	}

	@Override
	public String getRowKey(InfoEntry infoEntry) {
		// TODO Auto-generated method stub
		return "param{param}";
	}
	
	public Set<String> getRowKeys(InfoEntry infoEntry) {
		// TODO Auto-generated method stub
	    Set<String> rowKeyList = new HashSet<String>();
		Map<String,String> paramMap = infoEntry.getParams();//信息map
		Iterator<Entry<String, String>> it = paramMap.entrySet().iterator();
		while(it.hasNext())
		{
			Entry<String, String> entry = it.next();
			String key = entry.getKey(); //6821
			String value = entry.getValue(); //513660|513661
			if(careValues.containsKey(key))
			{
				rowKeyList.add(key+"="+value);
			}
			else if(careValues.containsKey(key+"="+value))
			{
				rowKeyList.add(key+"="+value);
			}
		}
		return rowKeyList;
	}
}
